package com.vm.osm.business.util;

import com.vm.osm.business.common.Constants;
import org.apache.log4j.Logger;

import javax.servlet.http.HttpServletRequest;

/** 获取用户缓存数据
 * Created by zhangshilin on 2018/2/6.
 */
public class UserDataUtil {

    private static Logger LOG = Logger.getLogger(UserDataUtil.class);


    //当前企业编号
    public static String getUserSelectedEnterpriseId(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        String enterpriseId = RedisUtil.get(sessionId+"_selected_enterprise_id");
        LOG.info("enterpriseId:"+enterpriseId);
        System.out.println("enterpriseId:"+enterpriseId);
        return enterpriseId;
    }
    //当前企业名称
    public static String getUserSelectedEnterpriseName(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_selected_enterprise_name");
    }
    //当前用户名称
    public static String getStaffName(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_staff_name");
    }
    //获取部门ID
    public static String getDepartmentId(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        String departmentId = RedisUtil.get(sessionId+"_department_id");
        LOG.info("departmentId:"+departmentId);
        System.out.println("departmentId:"+departmentId);
        return departmentId;

    }

    //当前用户头像
    public static String getStaffHeadImg(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_head_img");
    }
    //当前用户编号
    public static String getStaffId(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        String staffId = RedisUtil.get(sessionId+"_staff_id");
        LOG.info("staffId:"+staffId);
        System.out.println("staffId:"+staffId);
        return staffId;
    }
    public static String getAccessToken(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_access_token");
    }
    //当前账号编号
    public static String getAccountId(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_account_id");
    }
    //当前企业开通的数据权限范围(1全部2部门及子部门3部门4员工)
    public static String getEnterpriseDataRole(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_data_role");
    }

    public static String getStaffPhone(HttpServletRequest request){
        String sessionId = request.getHeader(Constants.SESSION_ID);
        return RedisUtil.get(sessionId+"_phone");
    }
}
